<?php
/**
 *  NevuxBB - Free Forum Software
 *  Copyright (C) 2008, 2010 NevuxBB (No one specific author)*  This program is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation, either version 3 of the License, or
 *  (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
 *
 * Ajax functions file
 * File: ajax.php
 * Purpose: Serve ajax pages
 * Todo: refine
 *
 */

// tell it were in remote
$up1l = true;
require('../system/files/global.php');

// what data needs to be sent back
switch($_REQUEST['sec']) {
	case 1:
		// username availability checker
		$result = Db_Abstraction::num_rows(Db_Abstraction::query("SELECT `user_id` FROM `nbb_users` WHERE `user_name` = '" . Db_Abstraction::clean($_POST['username']) . "' LIMIT 1;"));
		
		// how many results?
		if($result > 0) {
			// is a result
			echo('1');
		} else {
			// no results
			echo('0');
		}
		
		// end
		break;
	case 2:
		// bbcode live preview
		if(!empty($_REQUEST['data'])) {
			// is some data, parse it
			require('../system/external/libraries/NBBC/nbbc.php');
				// begin bbcode class
				$bbcode = new BBCode;
	
				// set smiley directories
				#$bbcode->SetSmileyURL("../smileys"); NEED TO BE CONFIGURABLE FOR DIFFERENT TEMPLATES
				#$bbcode->SetSmileyDir("../smileys");
				
				// settings
				$bbcode->SetTagMarker('[');
				$bbcode->SetAllowAmpersand(true);
				$bbcode->SetEnableSmileys(false);
				$bbcode->SetDetectURLs(true);
				$bbcode->SetPlainMode(false);
				
				// parse
				$output = $bbcode->Parse($_REQUEST['data']);
				
				// return back to user
				echo($output);
		} else {
			// empty, return false
			return false;
		}
		
		// end
		break;
}
?>
